using System.Collections.Generic;
using System.Collections;

namespace SharpPlanetsModel {

  public class Rocket: SpaceObject {
    private double _Xspeed;
    private double _Yspeed;
    private List<Position> Track;

    public Rocket(Position startPos) {
      CenterPosition = startPos;
      //throw new System.NotImplementedException();
      Track = new List<Position>();
      Track.Add(startPos);
    }

    public double Xspeed {
      get {
        return _Xspeed;
      }
      set {
        if ((value < Configuration.maxRealSpeedValue) && (value > Configuration.minRealSpeedValue))
          _Xspeed = value;
        else
          _Xspeed = 0;
      }
    }

    public double Yspeed {
      get {
        return _Yspeed;//throw new System.NotImplementedException();
      }
      set {
        if ((value < Configuration.maxRealSpeedValue) && (value > Configuration.minRealSpeedValue))
          _Yspeed = value;
        else
          _Yspeed = 0;
      }
    }

    /// <summary>
    /// add a position to the rocket track
    /// </summary>
    /// <param name="Pos">the rocket's current position</param>
    public void AddPosition(Position Pos) {
      Track.Add(Pos);
    }

    /// <summary>
    /// clean-up of the list of positions
    /// </summary>
    public void PositionTrackClear() {
      Track.Clear();
    }

    override public void Paint(System.Drawing.Graphics graph) {
      //int RealWidth = (int)(graph.ClipBounds.Width);
      //int RealWidth = 320;
      ////int hlx = this.CenterPosition.getXRel(RealWidth) - 3;
      ////int hly = this.CenterPosition.getYRel(RealWidth) - 3;
      ////System.Drawing.Rectangle myRect = new System.Drawing.Rectangle(hlx, hly, 6, 6);
      ////System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
      ////graph.FillEllipse(myBrush,myRect);
      if (Track.Count > 1) {
        int OldPosX, PosX, OldPosY, PosY;
        OldPosX = CenterPosition.getXRel(Configuration.fieldWidthInPixels);
        OldPosY = CenterPosition.getYRel(Configuration.fieldWidthInPixels);
        System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Yellow);
        foreach (Position currPos in Track) {
          PosX = currPos.getXRel(Configuration.fieldWidthInPixels);
          PosY = currPos.getYRel(Configuration.fieldWidthInPixels);
          graph.DrawLine(myPen, OldPosX, OldPosY, PosX, PosY);
          OldPosX = PosX;
          OldPosY = PosY;
        }
      }
    }
  }
}
